package com.bwie.doctor.controller;

import com.bwie.common.core.domain.Result;
import com.bwie.doctor.domain.dto.AddArticleDTO;
import com.bwie.doctor.domain.dto.UpdArticleDTO;
import com.bwie.doctor.domain.vo.ArticleDetailVo;
import com.bwie.doctor.domain.vo.ArticleDraftVo;
import com.bwie.doctor.domain.vo.ArticleListVo;
import com.bwie.doctor.service.DoctorArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("doctorArticle")
public class DoctorArticleController {
    /**
     * 注入
     */
    @Autowired
    private DoctorArticleService service;

    /**
     * 获得所有文章列表
     * @return
     */
    @GetMapping("getAllArticle")
    public Result<List<ArticleListVo>> getAllArticle() {
        //获得所有文章列表
        List<ArticleListVo> list = service.getAllArticle();
        //返回
        return Result.success(list);
    }

    /**
     * 医生添加文章/草稿
     * @param addArticleDTO
     * @return
     */
    @PostMapping("addArticle")
    public Result addArticle(@RequestBody AddArticleDTO addArticleDTO) {
        //添加文章
        service.addArticle(addArticleDTO);
        //返回
        return Result.success();
    }

    /**
     * 获得医生文章草稿列表
     * @return
     */
    @GetMapping("getDraft")
    public Result<List<ArticleDraftVo>> getDraft() {
        //获得所有文章列表
        List<ArticleDraftVo> list = service.getDraft();
        //返回
        return Result.success(list);
    }

    /**
     * 获得医生发布的视频文章列表
     * @return
     */
    @GetMapping("getDoctorVideoArticle/{type}")
    public Result<List<ArticleListVo>> getDoctorVideoArticle(@PathVariable Integer type) {
        //获得医生发布的视频文章列表
        List<ArticleListVo> list = service.getDoctorVideoArticle(type);
        //返回
        return Result.success(list);
    }

    /**
     * 医生删除草稿
     * @param id
     * @return
     */
    @DeleteMapping("delDraft/{id}")
    public Result delDraft(@PathVariable Long id){
        //删除草稿
        service.delDraft(id);
        //返回
        return Result.success();
    }

    /**
     * 医生修改草稿
     * @param updArticleDTO
     * @return
     */
    @PutMapping("updDraft")
    public Result updDraft(@RequestBody UpdArticleDTO updArticleDTO){
        //修改草稿
        service.updDraft(updArticleDTO);
        //返回
        return Result.success();
    }

    /**
     * 医生查看文章详情
     * @param id
     * @return
     */
    @GetMapping("getArticleDetail/{id}")
    private Result<ArticleDetailVo> getArticleDetail(@PathVariable Long id){
        //搜搜文章详情
        ArticleDetailVo articleDetailVo = service.getArticleDetail(id);
        //返回
        return Result.success(articleDetailVo);
    }
}